#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
//////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2014 Audiokinetic Inc. / All Rights Reserved
//
//////////////////////////////////////////////////////////////////////

using UnityEngine;
using System.Collections.Generic;

namespace AudioStudio
{
    [AddComponentMenu("Wwise/AkEnvironment")]
    [RequireComponent(typeof(Collider))]
    /// @brief Use this component to define a reverb zone.  This needs to be added to a collider object to work properly. \ref unity_use_AkEvironment_AkEvironmentPortal
    /// @details This component can be attached to any collider.  You can specify a roll-off to fade-in/out of the reverb.  
    /// The reverb parameters will be defined in the Wwise project, by the sound designer.  All AkGameObj that are 
    /// "environment"-aware will receive a send value when entering the attached collider.
    /// \sa
    /// - \ref unity_use_AkEvironment_AkEvironmentPortal
    public class AkEnvironment : MonoBehaviour
    {
        public const int MAX_NB_ENVIRONMENTS = 4;

        public class AkEnvironment_CompareByPriority : IComparer<AkEnvironment>
        {
            public virtual int Compare(AkEnvironment a, AkEnvironment b)
            {
                int result = a.priority.CompareTo(b.priority);

                if (result == 0 && a != b)
                    return 1;
                else
                    return result;
            }
        }

        static public AkEnvironment_CompareByPriority s_compareByPriority = new AkEnvironment_CompareByPriority();

        ///The selection algorithm is as follow: 
        /// -# Environments have priorities.
        /// -# Environments have a "Default" flag. This flag effectively says that this environment will be bumped out if any other is present.
        /// -# Environments have an "Exclude Other" flag. This flag will tell that this env is not overlappable with others. So, only one (the highest priority) should be selected.
        public class AkEnvironment_CompareBySelectionAlgorithm : AkEnvironment_CompareByPriority
        {
            public override int Compare(AkEnvironment a, AkEnvironment b)
            {
                if (a.isDefault)
                {
                    return (b.isDefault) ? base.Compare(a, b) : 1;
                }
                else if (b.isDefault)
                {
                    return -1;
                }
                else if (a.excludeOthers)
                {
                    return (b.excludeOthers) ? base.Compare(a, b) : -1;
                }
                else
                {
                    return (b.excludeOthers) ? 1 : base.Compare(a, b);
                }
            }
        }

        static public AkEnvironment_CompareBySelectionAlgorithm s_compareBySelectionAlgorithm = new AkEnvironment_CompareBySelectionAlgorithm();

#if UNITY_EDITOR
        public byte[] valueGuid = new byte[16];
#endif

        public int m_auxBusID;

        public AuxBus auxBus;

        //Cache of the colliders for this environment, to avoid calls to GetComponent.
        private Collider m_Collider;

        //smaller number has a higher priority
        public int priority = 0;

        //if isDefault, then this environment will be bumped out if any other is present 
        public bool isDefault = false;

        //if excludeOthers, then only the environment with the excludeOthers flag set to true and with the highest priority will be active
        public bool excludeOthers = false;

        public uint GetAuxBusID()
        {
            return (uint)m_auxBusID;
        }

        public void SetAuxBusID(int in_auxBusID)
        {
            m_auxBusID = in_auxBusID;
        }

        public float GetAuxSendValueForPosition(Vector3 in_position)
        {
            return 1;
        }

        public Collider GetCollider()
        {
            return m_Collider;
        }

        public void Awake()
        {
            m_Collider = GetComponent<Collider>();
            if (auxBus != null)
                m_auxBusID = auxBus.ID;
        }
    }
}
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.